from model.skill import Skill


class Character:

    # 新建角色，选择阵营
    def __init__(self, name, camp):
        self.name = name
        self.camp = camp
        # 初始属性
        self.attack = 10
        self.blood_volume = 100
        self.defend = 10
        self.experience = 0
        self.rank = 1
        # 初始化人物技能
        skill_1 = Skill('致命一击', camp, introduction='致命一击：攻击时可以暴击，暴击率为（20 + 技能lv * 5）%，暴击伤害为（30 + 技能lv * 3）%')
        skill_2 = Skill('嗜血', camp, introduction='嗜血：攻击时附带吸血，吸血量为（5 + 技能lv * 1）%攻击造成的伤害，可以作用于致命一击')
        skill_3 = Skill('蘑菇王的遗愿', camp, introduction='蘑菇王的遗愿：遇到BOSS时伤害增加（10 + 技能lv * 5），可以作用于致命一击')
        skill_4 = Skill('助我成仙', camp, introduction='助我成仙：击杀怪物时候有（5 + 5 * 技能lv）%的几率夺取怪物（10 + 10 * 技能lv）%的全属性')
        skill_5 = Skill('以下克上', camp, introduction='以下克上：攻击比自己等级高的敌人时有（5 + 5 * 技能lv）%的几率增加（2 + 2 * 技能lv）%伤害')
        skill_6 = Skill('复仇之心', camp, introduction='复仇之心：受到攻击后(5 + 5 * 技能lv）%的几率永久增长(2 + 2 * 技能lv）攻击力')
        skill_7 = Skill('无尽怒火', camp, introduction='无尽怒火（借鉴LOL蛮子的大招)：濒死时有(1 + 1 * 技能lv）%的几率保持一滴血而不死亡')
        skill_x = Skill('神罗天征', camp, introduction='神罗天征: 击败修罗神帝后获得该技能，攻击时有（1 + 0.01 * 技能lv）%的几率直接秒杀怪物，包括BOSS')
        self.skills = [
            skill_1, skill_2, skill_3, skill_4, skill_5, skill_6, skill_7, skill_x
        ]
        self.gold = 0
        self.state = None
        self.reinforcement_factor = 1.0
        self.defeat_monster_num = 0  # 击败怪物数量
        self.resurrection_times = 0  # 复活次数

    def init(self):
        skill = []
        print('----------------------------------------------------')
        print(self.camp + ' 英雄 ' + self.name + ' 出世！')
        print('获得技能：阵营专属技能：')
        #  人族：升级快，中期全能王，修仙最容易飞升
        if self.camp == '人族':
            skill = Skill('快速升级', self.camp, '快速升级：人物升级所需经验减半', True)
            print('快速升级：人物升级所需经验减半')
        #  兽族：基础属性高，前期打架猛
        elif self.camp == '兽族':
            skill = Skill('野蛮体魄', self.camp, '野蛮体魄：升级增加的基础属性提高', True)
            print('野蛮体魄：升级增加的基础属性提高')
        #  暗夜精灵族： 天赋高，技能修炼效率提高50%，后期DPS
        elif self.camp == '暗夜精灵':
            skill = Skill('绝佳天赋', self.camp, '绝佳天赋：技能升级所需经验减半', True)
            print('绝佳天赋：技能升级所需经验减半')
        self.skills.append(skill)
        print('----------------------------------------------------')

    # 计算等级
    def get_rank(self):
        count = 50 * self.reinforcement_factor
        if self.name == 'GM':
            count = 10
        if self.camp == '人族':
            count *= 0.5
        elif self.camp == '兽族':
            count *= 1.0
        elif self.camp == '暗夜精灵':
            count *= 0.9
        while self.experience > self.rank * count:
            self.experience -= self.rank * count
            self.upgrade()
        return self.rank, self.rank * count

    def print_state(self):
        current_rank, next_rank_need_experience = self.get_rank()
        str_skills = ''
        for i in self.skills:
            if i.is_learn:
                i_rank, i_exp = i.get_rank()
                str_skills += str(i.name) + 'lv' + str(i.rank) + '(' + str(i.experience) + '/' + str(i_exp) + ')' + ' '
        print('----------------------------------------------------')
        print(
            '\033[0;36;40m角色名：' + self.name + '\n等级：' + str(current_rank) + '\n阵营：' + self.camp + '\n攻击力：' + str(
                self.attack) + '\n血量：' + str(
                self.blood_volume) + '\n防御力：' + str(self.defend) + '\n经验值:' + str(self.experience) + '/' + str(
                next_rank_need_experience) + '\n技能：' + str_skills + '\033[0m')
        if self.state is not None:
            print('\033[0;36;40m境界:', self.state, '强化系数：', self.reinforcement_factor, '\033[0m')

    # 人物升级
    def upgrade(self):
        self.rank += 1
        #  人族：升级快，中期全能王
        if self.camp == '人族':
            self.attack += 3 * self.reinforcement_factor
            self.blood_volume += 34 * self.reinforcement_factor
            self.defend += 1.2 * self.reinforcement_factor
        #  兽族：基础属性高，前期打架猛
        elif self.camp == '兽族':
            self.attack += 5 * self.reinforcement_factor
            self.blood_volume += 50 * self.reinforcement_factor
            self.defend += 3 * self.reinforcement_factor
        #  暗夜精灵族： 天赋高，技能修炼效率提高50%，后期DPS
        elif self.camp == '暗夜精灵':
            self.attack += 2.5 * self.reinforcement_factor
            self.blood_volume += 50 * self.reinforcement_factor
            self.defend += 1.5 * self.reinforcement_factor

        if self.rank > 100:
            self.reinforcement_factor += 1
        print('----------------------------------------------------')
        print("\033[0;33;40m {}升级了！ {} -> {} \033[0m".format(self.name, self.rank - 1, self.rank))

    # 学习新技能
    def learn_new_skill(self, skill_name):
        self.skills.append(skill_name)

    def start_xiuxian(self):
        self.attack *= 10
        self.blood_volume *= 10
        self.defend *= 10
